<template>
	<view style="font-size: 16px">
		<view style="margin-top: 30px">

		</view>
		
		<uni-section title="消息提醒：" type="">
			<label style="color: #f30; font-size: 14px">增加日报总结、一键复制、搜索功能。</label>
		</uni-section>
		<uni-list>
			<uni-list-item  title="今日日志" :rightText="record_flag == null ? '' : (record_flag ? '已提交' : '未提交')" 
				link to="/pages/tabBar/log/index"
				showArrow="true" :style="{fontSize: '14px', color: record_flag ? '#0f0' : '#f00'}"></uni-list-item>
			<!-- <uni-list-item  title="消息提醒" showArrow="true" :show-badge="true" badge-text="0" ></uni-list-item> -->
		</uni-list>


		<uni-section title="进行中的任务" type="">
			<label style="font-size: 14px; color: #00f" @click="editLeftJob">一键填报 
				<uni-icons type="arrowright" size="15" style="margin-left: 5px; color: #bbb"></uni-icons>
			</label>
		</uni-section>
		<uni-list>
			<uni-list-item v-for="task in leftTasks" :title="task.task + (level < 1 ? '' : '\t, ' + task.user)" 
				showArrow="true" :show-badge="true" :badge-text="task.progress+'%'" ></uni-list-item>
		</uni-list>
		
		<!--一键填报选择-->
		<uni-popup id="selTask" ref="dialogSelTask" type="dialog">
			<view style="width: 100%; background: #fff; padding: 5px 20px; border-radius: 15px;box-sizing:border-box" class="createPop">
				<view style="text-align: center; margin: 15px 0px; color: #007aff"> 一键填报 </view>
				<form style="font-size: 14px">
					<view style="min-height: 200px; max-height: 500px; overflow-y: scroll;">
						<!-- 完成内容 -->
						<view class="uni-padding-wrap" style=" margin-bottom: 10px">
							<view class="uni-title uni-common-mt" style="font-size: 16px">今日内容：</view>
						</view>
						<view class="uni-list" style="border-top: 1px solid #ddd;">
							<checkbox-group @change="selLeftChange($event, 0)">
								<view v-for="t in leftTasks" :key="t.task" class="uni-form-item uni-column; " 
									style="min-height: 40px; display: flex; flex-direction: row; border-bottom: 1px solid #ddd">
									<checkbox style="width: 35px; margin: auto; " :value="taskKey(t)" :checked="false" />
									<view style="flex: 1; margin: auto; font-size: 13px; color: #666">{{t.task}}</view>
								</view>
							</checkbox-group>
						</view>
						<!-- 计划情况 -->
						<view class="uni-padding-wrap" style=" margin: 15px 0px">
							<view class="uni-title uni-common-mt" style="font-size: 16px">明日计划：</view>
						</view>
						<view class="uni-list" style="border-top: 1px solid #ddd;">
							<checkbox-group @change="selLeftChange($event, 1)">
								<view v-for="t in leftTasks" :key="t.task" class="uni-form-item uni-column; " 
									style="min-height: 40px; display: flex; flex-direction: row; border-bottom: 1px solid #ddd">
									<checkbox style="width: 35px; margin: auto; " :value="taskKey(t)"
										:checked="false" />
									<view style="flex: 1; margin: auto; font-size: 13px; color: #666">{{t.task}}</view>
								</view>
							</checkbox-group>
						</view>
						
					</view>
					<view style="text-align: center; display: flex; justify-content: space-between; padding: 15px 25px">
						<button class="mini-btn" type="default" size="mini" @click="cancelLeftTask">取消</button>
						<button class="mini-btn" type="primary" size="mini" @click="submitLeftTask">确认</button>
					</view>
				</form>
			</view>
		</uni-popup>


	</view>
</template>

<script>
	import Utils from "../../js/utils";
	export default {
		data() {
			return {
				record_flag: null,
				title: 'Hello',
				leftTasks: [],
				level: 0,
				selJobs: [],
				selPlans: [],
				current: 0,
				
				// 视频测试
				imagePath: '',
				videoPath: ''
			}
		},
		onLoad() {
			Utils.getCache('token').then(d => {
				
			}).catch(d => {
				uni.navigateTo({
					url: "/pages/index/login"
				});
			})
		},
		onReady() {
			
		},
		onShow() {
			this.checkRecordStatus();
			this.getTaskLeft();
		},
		methods: {
			checkRecordStatus () {
				Utils.ajax("/getSubmitStatus", {}).then( res => {
					this.record_flag = res.data;
				});
			},
			clickRecordStatus () {
				uni.navigateTo({
					url: "/pages/tabBar/log/index"
				});
			},
			getTaskLeft () {
				let lv = Utils.getCacheSync('level');
				this.level = lv ? parseInt(lv) : 0;
				let orgId = Utils.getCacheSync('orgId');
				let param = (this.level > 1) ? {'department': orgId} : {};
				Utils.ajax("/getTaskLeft", param).then( res => {
					this.leftTasks = res.data;
				});
			},
			taskKey(task) {
				return [task.project, task.module, task.task].join("$_$");
			},
			editLeftJob () {
				Utils.ajax("/getTaskLeft", {}).then( res => {
					this.leftTasks = res.data;
					this.selJobs = [];
					this.selPlans = [];
					this.$refs.dialogSelTask.open();
				});
			},
			cancelLeftTask () {
				this.$refs.dialogSelTask.close();
			},
			submitLeftTask () {
				if (this.selJobs.length == 0 && this.selPlans.length == 0) {
					uni.showToast({ title: "未选择任何项！", icon: 'success', mask: true, 
						duration: 1000});
					return;
				}
				let params = JSON.stringify({'jobs': this.selJobs, 'plans': this.selPlans});
				uni.navigateTo({
					url: "/pages/tabBar/log/index?tasks=" + params
				});
				this.$refs.dialogSelTask.close();
			},
			selLeftChange (e, idx) {
				if (idx) {
					this.selPlans = e.detail.value;
				} else {
					this.selJobs = e.detail.value;
				}
			}
		}
	}
</script>

<style>
	
	.text-area {
		display: flex;
		justify-content: center;
	}

</style>
